<?php 

// 这里是传customid获取passport信息，返回报文head是ok，则显示在相应的文件框内。
    $isDisplayPassportInfo = false;
    $obj = Mage::helper('passport');
    $custId = Mage::getSingleton('customer/session')->getCustomer()->getId();
    $result = $obj->getPassport($custId);
    $xmlobj = simplexml_load_string($result);
    if ($xmlobj->Head[0] == 'OK') {
        $isDisplayPassportInfo = true;
        $date = explode('-',$xmlobj->Body->IssueDate[0]);
    }
?>



<div class="page-title">
    <h1><?php echo $this->__('Edit Passport Information') ?></h1>
</div>

<?php if($this->getRequest()->getParam('messages')): ?>
	<ul class="messages">
	<li class="success-msg">
		<ul>
			<li><span><?php echo $this->__($this->getRequest()->getParam('messages')); ?></span></li>
		</ul>
	</li>
	</ul>
<?php endif ?>

<form name="passport" action="<?php echo $this->getUrl('passport/customer/setpassport') ?>" method="post" id="passport_validate" autocomplete="off">
    <div>
        <ul class="form-list">
            <li class="fields">
                <input type="hidden" name="AccountId" value="<?php echo $custId; ?>">
            </li>
            <li class="fields">
                <label class="required"><em>*</em><?php echo $this->__('Passport Number') ?></label>
                <div class="input-box">
                    <input type="text" name="PassportNo" id="PassportNo" class="input-text required-entry" <?php if($isDisplayPassportInfo){echo 'value="'. $xmlobj->Body->PassportNo[0] .'"';}?> />
                </div>
            </li>

            <li class="fields">
                <label class="required"><em>*</em><?php echo $this->__('First Name') ?></label>
                <div class="input-box">
                    <input type="text" name="FirstName" id="FirstName" class="input-text required-entry" <?php if($isDisplayPassportInfo) {echo 'value="'. $xmlobj->Body->FirstName[0] .'"';} ?>/>
                </div>
            </li>

            <li class="fields">
                <label><?php echo $this->__('Middle Name') ?></label>
                <div class="input-box">
                    <input type="text" name="MiddleName" id="MiddleName" class="input-text" <?php if($isDisplayPassportInfo) {echo 'value="'. $xmlobj->Body->MiddleName[0] .'"';} ?>/>
                </div>
            </li>

            <li class="fields">
                <label class="required"><em>*</em><?php echo $this->__('Last Name') ?></label>
                <div class="input-box">
                    <input type="text" name="LastName" id="LastName" class="input-text required-entry" <?php if($isDisplayPassportInfo) {echo 'value="'. $xmlobj->Body->LastName[0] .'"';} ?>/>
                </div>
            </li>

            <li class="fields">
                <label class="required"><em>*</em><?php echo $this->__('Issue Date') ?></label>
                <div class="input-box required-entry">
                    <select name=YYYY onchange="YYYYMM(this.value)" class="validate-select" style="width:100px;">
                        <option value="">YYYY</option>
                    </select>
                    <select name=MM onchange="MMDD(this.value)" class="validate-select" style="width:80px;">
                        <option value="">MM</option>
                    </select>
                    <select name=DD class="validate-select" style="width:80px;">
                        <option value="">DD</option>
                    </select>
                </div>
            </li>
        </ul>
    </div>

    <div class="buttons-set">
        <p class="back-link"><a href="<?php echo $this->getBackUrl() ?>"><small>&laquo; </small><?php echo $this->__('Back') ?></a></p>
        <button type="submit" title="<?php echo $this->__('Save') ?>" class="button"><span><span><?php echo $this->__('Save') ?></span></span></button>
        <p class="required"><?php echo $this->__('* Required Fields') ?></p>
    </div>
</form>

<script type="text/javascript">
//<![CDATA[
    var dataForm = new VarienForm('passport_validate', true);
//]]>
</script>


<script language="JavaScript">
    <!--
    window.onload = function(){
        strYYYY = document.passport.YYYY.outerHTML;
        strMM = document.passport.MM.outerHTML;
        strDD = document.passport.DD.outerHTML;
        MonHead = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

        //先给年下拉框赋内容
        var y = new Date().getFullYear();
        var str = strYYYY.substring(0, strYYYY.length - 9);
        for (var i = (y-30); i < (y+30); i++) //以今年为准，前30年，后30年
        {
            str += "<option value='" + i + "'> " + i + "</option>\r\n";
        }
        document.passport.YYYY.outerHTML = str +"</select>";

        //赋月份的下拉框
        var str = strMM.substring(0, strMM.length - 9);
        for (var i = 1; i < 13; i++)
        {
            str += "<option value='" + i + "'> " + i + "</option>\r\n";
        }
        document.passport.MM.outerHTML = str +"</select>";

        <?php
        if($isDisplayPassportInfo) {
            echo 'document.passport.YYYY.value =' . $date[0].";\r\n";
            echo 'document.passport.MM.value =' . $date[1].";\r\n";
        }
        ?>
        var n = MonHead[new Date().getMonth()];
        if (new Date().getMonth() ==1 && IsPinYear(YYYYvalue)) n++;
        writeDay(n); //赋日期下拉框
        <?php
        if($isDisplayPassportInfo){
            echo 'document.passport.DD.value =' . $date[2] . ";\r\n";
        }
        ?>
    }
    function YYYYMM(str) //年发生变化时日期发生变化(主要是判断闰平年)
    {
        var MMvalue = document.passport.MM.options[document.passport.MM.selectedIndex].value;
        if (MMvalue == ""){DD.outerHTML = strDD; return;}
        var n = MonHead[MMvalue - 1];
        if (MMvalue ==2 && IsPinYear(str)) n++;
        writeDay(n)
    }
    function MMDD(str) //月发生变化时日期联动
    {
        var YYYYvalue = document.passport.YYYY.options[document.passport.YYYY.selectedIndex].value;
        if (str == ""){DD.outerHTML = strDD; return;}
        var n = MonHead[str - 1];
        if (str ==2 && IsPinYear(YYYYvalue)) n++;
        writeDay(n)
    }
    function writeDay(n) //据条件写日期的下拉框
    {
        var s = strDD.substring(0, strDD.length - 9);
        for (var i=1; i<(n+1); i++)
            s += "<option value='" + i + "'> " + i + "</option>\r\n";
        document.passport.DD.outerHTML = s +"</select>";
    }
    function IsPinYear(year)//判断是否闰平年
    { return(0 == year%4 && (year%100 !=0 || year%400 == 0))}
    -->
</script>
